#include "tcpthread.h"
#include <QPixmap>
#include <QFile>
#include <QDebug>
#include <windows.h>
#include <QTime>
#include <QSize>


tcpthread::tcpthread(QObject *parent) : QObject(parent)
{
}


void tcpthread::showjpg(QByteArray arr,int length)
{
    int begin_point=0,over_point=0,flag=0;
    for(int i=0;i<length;i++)
    {
        if(arr[i]=='\xff')
        {
            if(arr[i+1]=='\xd8')
            {
                flag=1;
                begin_point=i;

            }

            else if(flag==1 && arr[i+1]=='\xd9')
            {
                QSize picsize(600,600);
                QByteArray myarr=arr;
                over_point = i+1;
                myarr.remove(0,begin_point);
                myarr.resize(length-begin_point);
                int len =length-over_point-begin_point;
                myarr.remove(over_point+1,len);
                myarr.resize(length-begin_point-len+1);

                begin_point=0;over_point=0;flag=0;
                QPixmap pix;
                pix.loadFromData(myarr);
                showimage->setAlignment(Qt::AlignCenter);
                showimage->setPixmap(pix.scaled(picsize,Qt::KeepAspectRatio,Qt::SmoothTransformation));
            }
        }
    }



}


